<?php

namespace app\common\model;

use think\Model;
class Carcategory extends Model
{
    protected $resultSetType = 'collection';
    public static function get_category_list($type,$position)
    {
        $where = "status = '1'";
        $field = "id,name,cate_image";
        $order = "weigh DESC,add_time DESC";
        $list = self::where($where)->field($field)->order($order)->select()->toArray();
        if($type == 1){
            $cate_image = splicing_domain("/uploads/cate.png");
            // 新的一维数组
            $newCategory = ['id'=> 0,'name'=>'全部','cate_image'=>$cate_image];
            if(isset($position) && $position == 1){
                // 在原始数组前面追加新的一维数组
                array_unshift($list, $newCategory);
            }else{
                // 在原始数组末尾追加新的一维数组
                array_push($list, $newCategory);
            }
        }
        return $list;
    }

    public function getCateImageAttr($value)
    {
        if($value){
            return splicing_domain($value);
        }else{
            return "";
        }
    }
}
